using Godot;
using System;

public partial class HUD : CanvasLayer
{
	[Signal]
	public delegate void StartGameEventHandler();
	
	public void ShowMessage(string text)
{
	var message = GetNode<Label>("Message");
	message.Text = text;
	message.Show();

	GetNode<Timer>("MessageTimer").Start();
}

async public void ShowGameOver()
{
	ShowMessage("Game Over");

	var messageTimer = GetNode<Timer>("MessageTimer");
	await ToSignal(messageTimer, Timer.SignalName.Timeout);

	var message = GetNode<Label>("Message");
	message.Text = "Dodge the Creeps!";
	message.Show();

	await ToSignal(GetTree().CreateTimer(1.0), SceneTreeTimer.SignalName.Timeout);
	GetNode<Button>("StartButton").Show();
}

public void UpdateScore(int score)
{
	GetNode<Label>("ScoreLabel").Text = score.ToString();
}

// We also specified this function name in PascalCase in the editor's connection window.
private void OnStartButtonPressed()
{
	GetNode<Button>("StartButton").Hide();
	EmitSignal(SignalName.StartGame); //触发事件
}

// We also specified this function name in PascalCase in the editor's connection window.
private void OnMessageTimerTimeout()
{
	GetNode<Label>("Message").Hide();
}

}
